package com.zte.market.service.otherService.otherImpl;

import com.zte.login.service.UserService;
import com.zte.market.mapper.otherMapper.CTypeMapper;
import com.zte.market.pojo.otherPojo.CType;
import com.zte.market.service.otherService.CBrandService;
import com.zte.market.service.otherService.CTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品类型
 *
 * @Auther: 许月
 * @Date: 2022/10/06/19:32
 */
@Service
public class CTypeServiceImpl implements CTypeService {


    @Autowired
    private CTypeMapper cTypeMapper;

    @Autowired
    private UserService userService;

    @Autowired
    private CBrandService cBrandService;




    /**
     * 通过商品类型 id 查询商品类型信息
     *
     * @param typeId
     * @return
     */
    @Override
    public CType getByTypeId(Integer typeId) {
        CType cType = cTypeMapper.queryByTypeId(typeId);
        //设置创建人信息
        cType.setCreateUser(userService.getUserById(cType.getCreateId()));
        //设置品牌信息
        cType.setCBrand(cBrandService.getByBrandId(cType.getBrandId()));
        return cType;
    }

    /**
     * 通过 品牌id 获取所有的 商品类型 的列表
     *
     * @param brandId
     * @return
     */
    @Override
    public List<CType> getAllByBrandId(Integer brandId) {
        List<CType> cTypeList = cTypeMapper.queryAllByBrandId(brandId);
        for (CType cType : cTypeList) {
            //设置创建人信息
            cType.setCreateUser(userService.getUserById(cType.getCreateId()));
            //设置品牌信息
            cType.setCBrand(cBrandService.getByBrandId(cType.getBrandId()));
        }
        return cTypeList;
    }
}
